<?
include("../php/conni.php");

//获取CUST的项目
$query="select * from cust_item order by item asc";
if($result=$conni->query($query))
{
	$i=0;
	while($row=$result->fetch_assoc())
	{
		$cust_item[$i]=$row;
		$i++;
	}
}
//获取用户
$query="select * from user where status='A' order by ord asc";
if($result=$conni->query($query))
{
	$i=0;
	while($row=$result->fetch_assoc())
	{
		$user[$i]=$row;
		$i++;
	}
}

if($_GET[item]=='edit')
{
	//print_r($_GET);
	$query="select * from cust where id='".$_GET[id]."'";
	//echo $query;
	if($result=$conni->query($query))
	{
		$cust=$result->fetch_assoc();
		if($cust[sex]=='M'||$cust[sex]=='m')
		{
			$cust_sex_m='checked';
		}
		else
		{
			$cust_sex_f='checked';
		}

		//血型
		if($cust[blood]=='A')
		{
			$cust_blood_a='selected';
		}
		if($cust[blood]=='B')
		{
			$cust_blood_b='selected';
		}
		if($cust[blood]=='AB')
		{
			$cust_blood_ab='selected';
		}
		if($cust[blood]=='O')
		{
			$cust_blood_o='selected';
		}

	}
}
//获取拜访记录
$query="select *,user.name,cust_visit_type.text  from cust_visit left join user on cust_visit.v_user=user.id left join cust_visit_type on cust_visit.v_type=cust_visit_type.val  where cust_visit.v_cust_id='".$_GET[id]."'    order by cust_visit.op_num desc";
//echo $query;

if($result=$conni->query($query))
{
	$i=0;
	while($row=$result->fetch_assoc())
	{
		$visit[$i]=$row;
		$i++;
	}

	$t_sum=0;

	for($i=0;$i<count($visit);$i++)
	{
		$t_sum+=$visit[$i][v_sum];
	}
}
//print_r($visit);

//获取拜访类型
$query="select text,val from cust_visit_type where fn='cust_visit_type' and item='visit_type' order by ord asc";
if($result=$conni->query($query))
{
	$i=0;
	while($row=$result->fetch_assoc())
	{
		$visit_type[$i]=$row;
		$i++;
	}
}
//echo $query;
//print_r($visit[type][0]);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../js/pub.js"></script>

<link href="../css/pub.css" rel="stylesheet" type="text/css" />

<link href="../css/cust_edit.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/cust_edit.js"></script>
<script language="javascript" type="text/javascript" src="../my97/WdatePicker.js"></script>
<script type="text/javascript">
var cust_id="<?=$cust[id];?>";
var item="<?=$_GET[item];?>";
</script>
<body>
	
	
	
	<!--[if ie6]> 外框 <![endif]-->
	<div class="cust_edit_body" id="cust_edit_body">

		<!--[if ie6]> 菜单 <![endif]-->
		<div class="ce_top_menu_body">
			<!--[if ie6]> 返回按钮 <![endif]-->
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_back">
				返回查询
			</div>
			<?
			if($_GET[item]!='edit')
			{
			?>
			<!--[if ie6]> 返回按钮 <![endif]-->
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_submit">
				提交新增记录
			</div>
			<?
			}
			if($_GET[item]=='edit')
			{
			?>
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_submit_edit">
				提交修改
			</div>
			<!--[if ie6]> 返回按钮 <![endif]-->
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_visit">
				添加/查看拜访记录
			</div>
			<?
			}
			?>
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_back_edit" style="display:none">
				返回编辑界面
			</div>
			<div class="pub_button_1 cet_button_1" id="cust_edit_button_submit_visit" style="display:none">
				提交拜访记录
			</div>

		</div>
		


		<!--[if ie6]> 整体内容外框 <![endif]-->

		<div id="a_s_body">



			<!--[if ie6]> 变化的外框 <![endif]-->
			<div id="visit_body" style="width:1000px;overflow:hidden;">
				<!--[if ie6]> 编辑栏目 <![endif]-->
				<div class="ce_edit_body" id="fn_edit"  >


					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								姓名：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="name" value="<?=$cust[name];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								性别：
							</div>
							<div class="cee_t_20">
								<div class="ecc_t_100">
									<input type="radio" class="pub_radio_2" name="sex" id="sex_m" checked value="M" <?=$cust_sex_m?>/>
								</div>
								<label class="ecc_t_100" for="sex_m">
									男
								</label>
								<div class="ecc_t_100">
									&nbsp;&nbsp;&nbsp;&nbsp;
								</div>
								<div class="ecc_t_100">
									<input type="radio" class="pub_radio_2" name="sex" id="sex_f" value="F" <?=$cust_sex_f?> />
								</div>
								<label class="ecc_t_100" for="sex_f">
									女
								</label>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								籍贯：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="nati" value="<?=$cust[nati];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								年龄/生日：
							</div>
							<div class="cee_t_20">
								<!--[if ie6]>  <input type="text" class="pub_text_2" style="width:185px" id="age" value="<?=$cust[age];?>"/> <![endif]-->
								<input class="Wdate pub_text_2" value="<?=$cust[age];?>" type="text" style="width:185px;height:26px;border:1px solid #cccccc;margin:1px 0 0 0" onfocus="WdatePicker({skin:'twoer'})" id="age" />
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								血型：
							</div>
							<div class="cee_t_20">
								<select id="blood" class="pub_select_2" style="width:197px">
									<option value="">不详</option>
									<option value="A" <?=$cust_blood_a;?>>A型</option>
									<option value="B" <?=$cust_blood_b;?>>B型</option>
									<option value="AB" <?=$cust_blood_ab;?>>AB型</option>
									<option value="O" <?=$cust_blood_o;?>>O型</option>
								</select>
								
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								星座：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="conste" value="<?=$cust[conste];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>


					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								手机A：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="cella" value="<?=$cust[cella];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								手机B：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="cellb" value="<?=$cust[cellb];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								座机：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="tel" value="<?=$cust[tel];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								传真：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="fax" value="<?=$cust[fax];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								私人邮箱：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="per_email" value="<?=$cust[per_email];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								工作邮箱：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="work_email" value="<?=$cust[work_email];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								QQ号码：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="qq" value="<?=$cust[qq];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								MSN：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="msn" value="<?=$cust[msn];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								微博：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="weibo" value="<?=$cust[weibo];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								微信：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="weixin" value="<?=$cust[weixin];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								个人网站：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="web" value="<?=$cust[web];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								地区：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="area" value="<?=$cust[area];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<div class="ce_edit_c_body">

						<div class="cee_ec_b_2">
							<div class="cee_t_10">
								公司名称：
							</div>
							<div class="cee_t_30">
								<input type="text" class="pub_text_2" style="width:345px" id="company" value="<?=$cust[company];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_2">
							<div class="cee_t_10">
								公司地址：
							</div>
							<div class="cee_t_30">
								<input type="text" class="pub_text_2" style="width:345px" id="cop_addr" value="<?=$cust[cop_addr];?>"/>
							</div>
						</div>
					</div>

					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								邮政编码：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="cop_code" value="<?=$cust[cop_code];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								公司网站：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="cop_web" value="<?=$cust[cop_web];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								行业：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="trade" value="<?=$cust[trade];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								部门：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="dept" value="<?=$cust[dept];?>"/>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								职务：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="title" value="<?=$cust[title];?>"/>
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								关系：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="rela" value="<?=$cust[rela];?>"/>
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								客户类型：
							</div>
							<div class="cee_t_20">
								<select id="type" class="pub_select_2" style="width:197px">
									<?
									for($i=0;$i<count($cust_item);$i++)
									{
										if($cust_item[$i][item]=='cust_type')
										{
											if($cust_item[$i][val]==$cust[type])
											{
												$selected="selected";
											}
											else
											{
												$selected="";
											}
									?>
											<option value="<?=$cust_item[$i][val];?>" <?=$selected;?>><?=$cust_item[$i][text];?></option>
									<?
										}
									}
									?>
								</select>
								
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								客户等级：
							</div>
							<div class="cee_t_20">
								<select id="lv" class="pub_select_2" style="width:197px">
									<?
									for($i=0;$i<count($cust_item);$i++)
									{
										if($cust_item[$i][item]=='cust_lv')
										{
											if($cust_item[$i][val]==$cust[lv])
											{
												$selected='selected';
											}
											else
											{
												$selected='';
											}
									?>
											<option value="<?=$cust_item[$i][val];?>" <?=$selected;?>><?=$cust_item[$i][text];?></option>
									<?
										}
									}
									?>
								</select>
								
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								所属人员：
							</div>
							<div class="cee_t_20">
								<select id="user_id" class="pub_select_2" style="width:197px">
								<?
								for($i=0;$i<count($user);$i++)
								{
									if($cust[user_id]!='')
									{
										if($user[$i][id]==$cust[user_id])
										{
											$selected='selected';
										}
										else
										{
											$selected='';
										}
									}
									else if(!$cust[user_id]||$cust[user_id]=='')
									{
										if($user[$i][id]==$_SESSION['user_id'])
										{
											$selected='selected';
										}
										else
										{
											$selected='';
										}
									}
								?>
									<option value="<?=$user[$i][id];?>" <?=$selected;?>><?=$user[$i][name];?></option>
								<?
								}
								?>
								</select>
								
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<div class="ce_edit_c_body_1">
						
						<div class="ce_edit_c_body_1_l">
							<div class="cee_ec_b_1">
								<div class="cee_t_10">
									备注：
								</div>
							</div>
						</div>
						<div class="ce_edit_c_body_1_l1">
							<textarea class="pub_textarea_1 ce_edit_c_body_1_l1_text" id="remark"></textarea>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>

				</div>

				<!--[if ie6]> 拜访记录 <![endif]-->
				<div class="ce_edit_body" id="fn_visit" style="display:none" >
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 客户信息 <![endif]-->
					<div class="ce_edit_c_body" >

						<div class="cee_ec_b_101" style="font-weight:bold">
							<?=$cust[name];?>
						</div>
						<div class="cee_ec_b_102" style="font-weight:bold">
							<?=$cust[company]?>
						</div>


					</div>
					<!--[if ie6]> 拜访总览 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								拜访次数：
							</div>
							<div class="cee_t_20">
								<?=count($visit);?>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								拜访总开销：
							</div>
							<div class="cee_t_20">
								￥<?=sprintf("%.2f", $t_sum);?>元
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								
							</div>
							<div class="cee_t_20">
								
							</div>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								拜访时间：
							</div>
							<div class="cee_t_20">
								<!--[if ie6]> <input type="text" class="pub_text_2" style="width:185px" id="visit_date" /> <![endif]-->
								<input class="Wdate pub_text_2"  type="text" style="width:185px;height:26px;border:1px solid #cccccc;margin:1px 0 0 0" onfocus="WdatePicker({skin:'twoer'})" id="visit_date" />
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								受访人数：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="visit_num" />
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								拜访人员：
							</div>
							<div class="cee_t_20">
								<select id="visit_user" class="pub_select_2" style="width:197px">
								<?
								for($i=0;$i<count($user);$i++)
								{
									if($_SESSION['user_id']==$user[$i][id])
									{
										$selected='selected';
									}
									else
									{
										$selected='';
									}
								?>
									<option value="<?=$user[$i][id];?>" <?=$selected;?>><?=$user[$i][name];?></option>
								<?
								}
								?>
								</select>
							</div>
						</div>


					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<!--[if ie6]> 项目内容条 <![endif]-->
					<div class="ce_edit_c_body">

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								拜访类型：
							</div>
							<div class="cee_t_20">
								<select id="visit_type" class="pub_select_2" style="width:197px">
								<?
								for($i=0;$i<count($visit_type);$i++)
								{
								?>
									<option value="<?=$visit_type[$i][val];?>" ><?=$visit_type[$i][text];?></option>
								<?
								}
								?>
								</select>
							</div>
						</div>


						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								地点：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="visit_loc" />
							</div>
						</div>

						<div class="cee_ec_b_1">
							<div class="cee_t_10">
								花费金额：
							</div>
							<div class="cee_t_20">
								<input type="text" class="pub_text_2" style="width:185px" id="visit_sum" />
							</div>
						</div>


					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<div class="ce_edit_c_body_1">
						
						<div class="ce_edit_c_body_1_l">
							<div class="cee_ec_b_1">
								<div class="cee_t_10">
									拜访记录：
								</div>
							</div>
						</div>
						<div class="ce_edit_c_body_1_l1">
							<textarea class="pub_textarea_1 ce_edit_c_body_1_l1_text" id="visit_remark"></textarea>
						</div>
					</div>
					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>




					<!--[if ie6]> 拜访记录显示 <![endif]-->

					<!--[if ie6]> 项目内容条 <![endif]-->
					<?
					for($i=0;$i<count($visit);$i++)
					{
					?>
					<div class="ce_edit_c_body_2">
						<div class="cee_ec_b_210">
							<div class="cee_t_201">
								<?=$visit[$i][v_date];?>
							</div>
							<div class="cee_t_201">
								<?=$visit[$i][v_loc];?>
							</div>
							<div class="cee_t_201">
								<?=$visit[$i][v_num];?>
							</div>
							<div class="cee_t_201">
								<?=$visit[$i][name];?>
							</div>
							<div class="cee_t_201">
								<?=$visit[$i][text];?>
							</div>
							<div class="cee_t_201" style="text-align:right">
								￥<?=sprintf("%.2f", $visit[$i][v_sum]);?>元
							</div>
						</div>
					</div>
					<div class="ce_edit_c_body_2">
						<div class="cee_ec_b_220">
							<?=$visit[$i][v_remark];?>
						</div>
					</div>

					<!--[if ie6]> 条目之间的分割线 <![endif]-->
					<div class="cee_line_1">
					</div>
					<?
					}
					?>






				</div>
			</div>


		</div>



	</div>


</body>
</html>